/*
 * RSDAO_Factory.java
 *
 * Created on March 23, 2007, 5:26 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.group1E.data;

import java.util.Map;
import java.util.TreeMap;

/** This is a factory to retrieve the needed DAO according to the RevenueSource type.
 *
 * @author Travis Kulbeth
 */
public class RSDAO_Factory {
    
    private static RSDAO_Factory instance = null;
    	//create the map
    Map<String,RevenueSourceDAO> map = new TreeMap<String,RevenueSourceDAO>();
    
    /** Creates a new instance of RSDAO_Factory */
    public RSDAO_Factory() {

        map.put("sale",SaleDAO.getInstance());
        map.put("rental",RentalDAO.getInstance());
        map.put("print", PrintOrderDAO.getInstance());
        map.put("conversion",ConversionDAO.getInstance());
        map.put("repair",SvcRepairDAO.getInstance());
        map.put("backup",BackupDAO.getInstance());
//        map.put("fee",FeeDAO.getInstance());
    }

    /** Builds the map and returns an instance of the RSDAO_Factory
     * 
     * @return instance
     */
    public static synchronized RSDAO_Factory getInstance() {
        if (instance == null) {
            instance = new RSDAO_Factory();
        }
        return instance;
    }

    
    /** Retrieves the appropriate DAO from the map according to the given key
     * 
     * @param id contains the key (RevenueSource type) needed to retrieve the DAO
     * @return the appropriate DAO
     */
    public synchronized RevenueSourceDAO getDAO(String id){
        return map.get(id);
    }
}
